package com.example.administrator.xiaoxiang.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.example.administrator.xiaoxiang.R;
import com.example.administrator.xiaoxiang.fragment.Rebatefragment.HotCommoditiesFragment;
import com.example.administrator.xiaoxiang.fragment.Rebatefragment.MyrebateFragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class RebateFragment extends Fragment implements View.OnClickListener {

    public static final String TAG = "RebateFragment";
    private TextView mTextView1, mTextView2;
    private FragmentManager mFragmentManager;
    private ScrollView scrollView_class;
    private LinearLayout mRelativeLayout;
    private boolean clickable;
    public RebateFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_rebate, container, false);
        scrollView_class= (ScrollView) view.findViewById(R.id.scrollView_class);
        mRelativeLayout= (LinearLayout) view.findViewById(R.id.rela_class);
        scrollView_class.scrollTo(0, mRelativeLayout.getMeasuredHeight() - scrollView_class.getHeight());
        mTextView1 = (TextView) view.findViewById(R.id.tv_rebate1);
        mTextView2 = (TextView) view.findViewById(R.id.tv_rebate2);
        mTextView1.setOnClickListener(this);
        mTextView2.setOnClickListener(this);

        mFragmentManager = getChildFragmentManager();
        changeFragment(new HotCommoditiesFragment(),false);
        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_rebate1:

                changeFragment(new HotCommoditiesFragment(),false);

                break;
            case R.id.tv_rebate2:

                changeFragment(new MyrebateFragment(),true);
                break;
        }

    }
    public void changeFragment(Fragment fragment,boolean isInit){
        FragmentTransaction transaction=mFragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_rebate1,fragment);

        transaction.commit();

        mTextView1.setClickable(isInit);
        mTextView2.setClickable(!isInit);
    }
}
